﻿using ConfExpert.Forms.Base;
using DevTeam;

using System;
using System.Data;

namespace ConfExpert.Forms.SatinAlma
{
    public partial class _WB : XForm
    {
        public _WB()
        {
            InitializeComponent();
        }

        private void WB_Load(object sender, EventArgs e)
        {

            DataSet d = ExecuteDataSet("GetWB", 75, new DateTime(2013, 4, 17));
            DataTable dt = d.Tables[0].Copy();
            d.Tables.RemoveAt(0);


            gvCust.Init(dt);
            gvCust.FormatAsNumber(2, "UnitPrice");

            gvProduct.Init(d.Tables[0]);
            gvProduct.AddDetailGrid(gvTop, "ProductId");
            gvTop.FormatAsNumber(2, "UnitPrice");

            gvProduct.AddColumn("Qty", typeof(decimal), "SUM(Child({FK}).Qty)");

            gvTop.FormatAsNumber(0, "Qty");
            gvProduct.FormatAsNumber(0, "Qty");
            gvTop.Columns["UnitPrice"].VisibleIndex = gvTop.Columns["Qty"].VisibleIndex + 1;


            gvTop.AddSummary("Qty");
            gvProduct.AddSummary("Qty");
            gvCust.AddSummary("Quantity");

            gvCust.BestFitColumns();
            gvProduct.BestFitColumns();
            gvTop.BestFitColumns();

            splitContainerControl1.AutoSize();

            btnKaydet.ItemClick += btnKaydet_ItemClick;
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvCust.EndEditing();
            gvCust.Update();

            if (gvTop.DataTable().GetChanges() != null)
                ExecuteNonQuery("UpdWB", gvTop.SerializeChanges());
        }
    }
}